<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>

<%@ page import="java.util.List,com.vs.model.ExpenseForm"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<title>Search Expenses</title>
<script src="js/1.7.1jquery.min.js"></script>
<script src="js/jquery.tabSlideOut.v1.3.js"></script>

<script src="js/jquery-1.9.0.js"></script>
<script src="js/jquery.ui.core.js"></script>
<script src="js/jquery.ui.widget.js"></script>
<script src="js/jquery.ui.datepicker.js"></script>

<script>
	$(function() {
		$(".datepicker").datepicker({
			altField : "#alternate",
			altFormat : "DD, d MM, yy"
		});
	});
</script>

<script type="text/javascript">
	$(function() {
		$('.slide-out-div').tabSlideOut({
			tabHandle : '.handle', //class of the element that will become your tab
			pathToTabImage : 'images/takeatestdrive.png', //path to the image for the tab //Optionally can be set using css
			imageHeight : '187px', //height of tab image           //Optionally can be set using css
			imageWidth : '31px', //width of tab image            //Optionally can be set using css
			tabLocation : 'right', //side of screen where tab lives, top, right, bottom, or left
			speed : 300, //speed of animation
			action : 'click', //options: 'click' or 'hover', action to trigger animation
			topPos : '400px', //position from the top/ use if tabLocation is left or right
			rightPos : '20px', //position from left/ use if tabLocation is bottom or top
			fixedPosition : true
		//options: true makes it stick(fixed position) on scroll

		});

	});
</script>
<script type="text/javascript" language="javascript">
	$(document).ready(
			function() {
				$('.adCntnr div.acco2:eq(0)').find('div.expand:eq(0)')
						.addClass('openAd').end().find('div.collapse:gt(0)')
						.hide().end().find('div.expand').click(
								function() {
									$(this).toggleClass('openAd').siblings()
											.removeClass('openAd').end().next(
													'div.collapse')
											.slideToggle().siblings(
													'div.collapse:visible')
											.slideUp();
									return false;
								});
			})
</script>

<script>
	function searchDetails() {
		//	alert("searchDetails called");
		//document.form[0].action = "fetchExpenses.do";
		//document.form[0].searchType.value = "search";
		//document.form[0].submit();
		//var st=document.getElementById("searchType").value;
		//alert("st="+st);
		document.getElementById("searchType").value = "search";
		//alert("searchDetails end");
	}

	function exportToExcel() {
		//alert("exportToExcel called");
		//document.form[0].action = "fetchExpenses.do";
		//document.form[0].searchType.value = "export";
		//document.form[0].submit();
		document.getElementById("searchType").value = "reportExcel";
		
		window.open('reportExcel.jsp','_blank');
		//alert("exportDetails end");
	}
	function exportToPDF() {
		//alert("exportDetails called");
		document.getElementById("searchType").value = "reportPDF";
		//alert("exportDetails end");
		window.open('PDFServlet','_blank');
	}

	function autoPopulate() {

	}
	
	function editExpense(val) {
		//	alert("selectProject called");
		//alert("val="+val);
		document.getElementById("expenseId").value = val;
		document.getElementById("action").value = "beforeEdit";
		//alert("selectProject end");
		document.getElementById("expenseForm").submit();
	}
	function deleteExpense(val) {
		//	alert("selectProject called");
		//alert("val="+val);
		document.getElementById("expenseId").value = val;
		document.getElementById("action").value = "delete";
		//alert("selectProject end");
		document.getElementById("expenseForm").submit();
	}
	function showFilter()
	{
		//alert("1");
		if(document.getElementById("showFilter").value=="true")
		{
			//alert("2");
			document.getElementById("searchDiv").style.display="";
			document.getElementById("filterHref").innerHTML="Hide Filter";
			document.getElementById("showFilter").value="false";
		}
		else
		{
			//alert("3");
			document.getElementById("searchDiv").style.display="none";
			document.getElementById("filterHref").innerHTML="Show Filter";
			document.getElementById("showFilter").value="true";
		}
		
	}
	
	function expenseTypeChanged(val)
	{
		//alert("1");
		//alert("val="+val.value);
		var label=val.options[val.selectedIndex].innerHTML;
		label=label.trim();
		//alert("label="+label);
		if(label=="labour")
		{
			document.getElementById("laborLabel").style.display="";
			document.getElementById("laborField").style.display="";
		}
		else
		{
			document.getElementById("laborLabel").style.display="none";
			document.getElementById("laborField").style.display="none";
		}
	}
</script>
</head>
<body>
	<%
		String projectId = "";
		if (session.getAttribute("projectId") != null) {
			projectId = session.getAttribute("projectId").toString();
			out.println("projectId=" + projectId);
		}
		System.out.println("displaying viewexpense jsp");
	%>
	<%-- <%@ include file="/include/sessionCheck.jsp"%> --%>

	<%@ include file="/include/header.jsp"%>

	<%@ include file="/include/menu.jsp"%>

	<!--right start-->
	<div class="right_div">

		<jsp:include page="/customError.jsp" />
		
		<div id="searchDiv" style="display: none">
			<input type="hidden" name="showFilter" id="showFilter" value="true" />
			<span class="head_font">Search Expenses</span>
			<div class="height20"></div>
			<html:errors />
			<%-- <html:javascript formName="expenseSearchForm" /> --%>
			<br />

			<form id="expenseForm" action="expense.do" method="post">
				<input type="hidden" name="expenseId" id="expenseId"></input> <input
					type="hidden" name="action" id="action" value="select"></input> <input
					type="hidden" name="expenseTypeId" id="expenseTypeId" value=""></input>
				<input type="hidden" name="searchType" id="searchType"
					value="search"></input>
			</form>

			<form id="expenseForm" action="fetchExpenses.do" method="post">

			</form>

			<html:form action="fetchExpenses.do" method="post">

				<input type="hidden" name="searchType" id="searchType"
					value="search" />
				<input type="hidden" name="action" value="select" />
				<input type="hidden" name="expenseProjectId" value="<%=projectId%>" />
				<div class="grey_box" id="searchFilter">
					<table border="0" cellspacing="0" cellpadding="5" width="95%">
						<tr>
							<td width="10%">Expense Amount</td>
							<td width="25%"><html:select property="expenseAmount"
									styleClass="input_text">
									<html:option value="">---Select---</html:option>
									<html:option value="1000"> > 1000 Rs</html:option>
									<html:option value="10000"> > 10000 Rs</html:option>
									<html:option value="100000"> > 100000 Rs</html:option>
								</html:select>
							</td>
							<td width="10%">Expense Type</td>
							<td width="25%"><html:select property="expenseTypeId"
									onchange="expenseTypeChanged(this)" styleClass="input_text">
									<html:option value="">---Select---</html:option>
									<logic:present name="expenseTypes" scope="session">
										<logic:iterate id="element" name="expenseTypes"
											scope="session">
											<option
												value='<bean:write name="element" property="expenseTypeId" /> '>
												<bean:write name="element" property="expenseType" />
											</option>
										</logic:iterate>
									</logic:present>
								</html:select>
							</td>
							<td width="10%" id="laborLabel" style="display: none">Labor
								Type</td>
							<td width="20%" id="laborField" style="display: none"><html:select
									property="laborTypeId" styleClass="input_text">
									<html:option value="">---Select---</html:option>
									<logic:present name="laborTypes" scope="session">
										<logic:iterate id="element" name="laborTypes" scope="session">
											<option
												value='<bean:write name="element" property="laborTypeId" /> '>
												<bean:write name="element" property="laborType" />
											</option>
										</logic:iterate>
									</logic:present>
								</html:select>
							</td>
						</tr>
						<tr>
							<td width="10%">Expense From Date</td>
							<td width="25%"><html:text property="expenseFromDate"
									styleClass="input_text datepicker"></html:text>
							</td>
							<td width="10%">Expense To Date</td>
							<td width="25%"><html:text property="expenseToDate"
									styleClass="input_text datepicker"></html:text>
							</td>
							<td width="10%">&nbsp;</td>
							<td width="20%">&nbsp;</td>
						</tr>
						<tr>
							<td width="10%"></td>
							<td width="25%"><html:submit property="search"
									onclick="javascript:searchDetails()" value="Search"
									styleClass="btn"></html:submit>
							</td>
							<td width="10%">&nbsp;</td>
							<td width="25%">&nbsp;</td>
							<td width="10%">&nbsp;</td>
							<td width="20%">&nbsp;</td>
						</tr>
					</table>

				</div>
			</html:form>
		</div>


		<%
			int total = 0;
			List<ExpenseForm> list = (List<ExpenseForm>) request
					.getAttribute("expensesList");
			if (list != null) {
				for (int i = 0; i < list.size(); i++) {
					total += Integer.parseInt(list.get(i).getExpenseAmount());
				}
			}
		%>

		<div class="expand" align="right">
			<a id="filterHref" href="#" onclick="showFilter()">Show Filter</a>
		</div>
		<logic:present name="expensesList" scope="request">
			<br />
			<span class="head_font">Expenses Results</span>
			<div class="height20"></div>
			<div>
				<table border="0" cellspacing="0" cellpadding="5" width="95%"
					class="grid">

					<tr>

						<th>Project Name</th>
						<th>Expense Type</th>
						<th>Notes</th>
						<th>Expense Date</th>
						<th>Pay Mode</th>
						<th>Amount</th>
						<th>Actions</th>
					</tr>
					<logic:iterate id="element" name="expensesList" scope="request">
						<tr>

							<td><bean:write name="element" property="expenseProjectName" />
							</td>
							<td><bean:write name="element" property="expenseTypeName" />
							</td>
							<td><bean:write name="element" property="notes" /></td>
							<td><bean:write name="element" property="expenseDate" /></td>
							<td><bean:write name="element" property="payMode" /></td>
							<td><bean:write name="element" property="expenseAmount" />
							</td>
							<td class="see_det_font"><a href='#'
								onclick='editExpense(<bean:write name="element"
											property="expenseId" />)'>Edit</a>&nbsp;

								<logic:present name="currentUser" scope="session">
									<logic:equal name="currentUser" property="userType"
										value="admin">
										<a href='#'
											onclick='deleteExpense(<bean:write name="element"
											property="expenseId" />)'>Delete</a>
									</logic:equal>
								</logic:present></td>
						</tr>

					</logic:iterate>

					<tr>

						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td class="see_det_font">Total</td>
						<td class="see_det_font"><%=total%> Rs</td>
						<td>&nbsp;</td>
					</tr>


				</table>
				<table border="0" cellspacing="0" cellpadding="5" width="95%">
					<tr>

						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;<html:button property="export"
								onclick="exportToExcel()" value="Export to Excel"
								styleClass="btn"></html:button>&nbsp;<html:button
								property="export" onclick="exportToPDF()" value="Export to PDF"
								styleClass="btn"></html:button>
						</td>
					</tr>
				</table>
			</div>

		</logic:present>

	</div>
	<!--right end-->

	<div class="clear"></div>

	<%@ include file="/include/footer.jsp"%>

</body>
</html>